package com.whmskj.xjlhbc.mobile.controller;

import com.whmskj.xjlhbc.core.AjaxResult;
import com.whmskj.xjlhbc.core.Page;
import com.whmskj.xjlhbc.domain.DailyAttendanceLogMasterTable;
import com.whmskj.xjlhbc.domain.SublistOfDailyAttendanceRecordsF;
import com.whmskj.xjlhbc.dto.QueryDto;
import com.whmskj.xjlhbc.service.ISublistOfDailyAttendanceRecordsFService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/kq")
@Tag(name = "考勤点名",description = "考勤点名")
public class KqController {

    @Autowired
    private ISublistOfDailyAttendanceRecordsFService service;

    @GetMapping("/list")
    @Operation(description = "考勤点名-列表")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class,SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult list(QueryDto param){
        List<SublistOfDailyAttendanceRecordsF> list = service.queryList(param);
        return Page.getDataTable(list);
    }
    @GetMapping("/pbzl")
    @Operation(description = "排班总览")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class,SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult pbzl(QueryDto param){
        List<Object> list = service.queryPbzl(param);
        return AjaxResult.success(list);
    }


    @GetMapping("/tj/list")
    @Operation(description = "考勤统计")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class,DailyAttendanceLogMasterTable.class})
    ))
    public AjaxResult tjList(QueryDto param){
        List<DailyAttendanceLogMasterTable> list = service.tjList(param);
        return Page.getDataTable(list);
    }

    @PostMapping("/addDailyAttendance")
    @Operation(description = "考勤点名-添加人员")
    public AjaxResult addDailyAttendance(@RequestBody SublistOfDailyAttendanceRecordsF body) throws Exception {
        boolean result = service.addDailyAttendance(body);
        if(result)
            return AjaxResult.success();
        return AjaxResult.error();
    }

    @PostMapping("/updateDailyAttendance")
    @Operation(description = "考勤点名-修改")
    public AjaxResult updateDailyAttendance(@RequestBody SublistOfDailyAttendanceRecordsF body){
        boolean result = service.updateDailyAttendance(body);
        if(result)
            return AjaxResult.success();
        return AjaxResult.error();
    }

    @PostMapping("/removeDailyAttendance/{id}")
    @Operation(description = "考勤点名-删除")
    public AjaxResult removeDailyAttendance(@PathVariable("id") String id){
        boolean result = service.removeDailyAttendance(id);
        if(result)
            return AjaxResult.success();
        return AjaxResult.error();
    }

}
